Use case: SMARTCARD communication in polling mode

Sequence diagram

SMARTCARD communication in polling mode

  @startuml
  participant "Application" as p1
  participant "HAL Smartcard driver" as p2

  == initialization and configuration ==

  == Smartcard Processing in polling mode ==
  alt polling
  p1->p2: HAL_SMARTCARD_Transmit(&hsmartcard,\n                                                 aTxBuffer,\n                                                DATA_TO_SEND_SIZE,\n                                                1000)
  note over p2 #00FF00
  Transmitting data ongoing
  end note

  p2-->p1: <color #Green> HAL_OK
  else
  p1->p2: HAL_SMARTCARD_Receive(&hsmartcard,\n                                                 aRxBuffer,\n                                                DATA_TO_RECEIVE_SIZE,\n                                                1000)
  note over p2 #00FF00
  Receiving data ongoing
  end note
  p2-->p1: <color #Green> HAL_OK
  end

  @enduml

Code snippet

HAL1

HAL2

#define DATA_TO_SEND_SIZE           256
#define DATA_TO_RECEIVE_SIZE       DATA_TO_SEND_SIZE

uint8_t aTxBuffer[] = " **** Smartcard Communication **** ";
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];

SMARTCARD_HandleTypeDef hsmartcard;


HAL_SMARTCARD_Init(&hsmartcard);




HAL_SMARTCARD_Receive(&hsmartcard, aRxBuffer,
                      DATA_TO_RECEIVE_SIZE, 1000);

HAL_SMARTCARD_Transmit(&hsmartcard, aTxBuffer,
                       DATA_TO_SEND_SIZE, 1000);
#define DATA_TO_SEND_SIZE           256
#define DATA_TO_RECEIVE_SIZE       DATA_TO_SEND_SIZE

uint8_t aTxBuffer[] = " **** Smartcard Communication **** ";
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];

hal_smartcard_handle_t hsmartcard;
hal_smartcard_config_t smartcard_config;

HAL_SMARTCARD_Init(&hsmartcard, HAL_SMARTCARD4);

/* add config for smartcard instance */
HAL_SMARTCARD_SetConfig(&hsmartcard, &smartcard_config);

HAL_SMARTCARD_Receive(&hsmartcard, aRxBuffer,
                      DATA_TO_RECEIVE_SIZE, 1000);

HAL_SMARTCARD_Transmit(&hsmartcard, aTxBuffer,
                       DATA_TO_SEND_SIZE, 1000);

Key changes

  1. The polling transmit/receive process is unchanged between HAL1 and HAL2.

  2. HAL2 introduces the handle/config model and requires configuring the SMARTCARD instance before communication.